package com.jctrip.hotel.route.service;

import com.jctrip.hotel.common.util.BeanUtil;
import com.jctrip.hotel.domain.entity.HtHotelMthdomInfo;
import com.jctrip.hotel.domain.entity.HtHotelStdInfo;
import com.jctrip.hotel.domain.entity.HtPricePolicy;
import com.jctrip.hotel.route.model.param.GetHotelInformationParam;
import com.jctrip.hotel.route.model.result.GetHotelInformationResult;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 获取酒店基础信息接口-服务
 */
@Service
public class GetHotelInformationService extends RouteService {

    public GetHotelInformationResult execute(GetHotelInformationParam param) {
        // 价格政策配置
        List<HtPricePolicy> htPricePolicies = getPricePolicies();
        List<String> sourceCodes = htPricePolicies.stream()
                .map(HtPricePolicy::getSourceCode)
                .collect(Collectors.toList());
        // 酒店标准信息
        HtHotelStdInfo htHotelStdInfo = getHotelStdInfo(param.getHotelId(), sourceCodes);
        HtHotelMthdomInfo htHotelMthdomInfo = null;
        if(sourceCodes.contains("MTHDOM")){
            htHotelMthdomInfo = getHotelMthdomInfo(param.getHotelId());
        }
        if (htHotelStdInfo == null && htHotelMthdomInfo == null) {
            throw new RuntimeException("无效的hotelId");
        }
        GetHotelInformationResult result = GetHotelInformationResult.builder().build();
        if(param.getHotelId().contains("MTHDOM")){
            BeanUtil.copyProperties(htHotelMthdomInfo,result);
            result.setLatitude(BigDecimal.valueOf(htHotelMthdomInfo.getLatitude()));
            result.setLongitude(BigDecimal.valueOf(htHotelMthdomInfo.getLongitude()));
            return result;
        }
        BeanUtil.copyProperties(htHotelStdInfo, result);
        return result;
    }
}
